package com.libbase.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.base.activity.BaseActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.libbase.R;
import com.libbase.glide.GlideUtil;
import com.libbase.widget.FadeRecyclewView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SnapActivity extends BaseActivity {

    @BindView(R.id.rcy_snap)
    RecyclerView rcy_snap;

    @BindView(R.id.rcy_snap_1)
    FadeRecyclewView rcy_snap_1;

    @BindView(R.id.rcy_snap_2)
    FadeRecyclewView rcy_snap_2;

    public static void startActivity(Context context) {
        Intent intent = new Intent(context, SnapActivity.class);
        context.startActivity(intent);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_snap;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        final Integer[] RES_ID = new Integer[]{
                R.drawable.image1,
                R.drawable.image2,
                R.drawable.image3,
                R.drawable.image4,
                R.drawable.image5,
                R.drawable.image6,
                R.drawable.image7,
                R.drawable.image8,
                R.drawable.image9,
                R.drawable.image10,
                R.drawable.image11,
                R.drawable.image12,
                R.drawable.image13
        };
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rcy_snap.setLayoutManager(manager);
        SnapAdapter adapter = new SnapAdapter();
        rcy_snap.setAdapter(adapter);
        adapter.setNewData(Arrays.asList(RES_ID));
        PagerSnapHelper snapHelper = new PagerSnapHelper();
        snapHelper.attachToRecyclerView(rcy_snap);


        LinearLayoutManager manager1 = new LinearLayoutManager(mContext);
        manager1.setOrientation(LinearLayoutManager.HORIZONTAL);
        rcy_snap_1.setLayoutManager(manager1);
        List<String> strings = new ArrayList<>();
        for (int i = 0; i < 21; i++) {
            strings.add("标题" + (i + 1));
        }
        SnapAdapter1 snapAdapter1 = new SnapAdapter1();
        rcy_snap_1.setAdapter(snapAdapter1);
        snapAdapter1.setNewData(strings);


        LinearLayoutManager manager2 = new LinearLayoutManager(mContext);
        manager2.setOrientation(LinearLayoutManager.VERTICAL);
        rcy_snap_2.setLayoutManager(manager2);
        rcy_snap_2.setOrientationMode(FadeRecyclewView.ORIENTATION.VERTICAL);
        List<String> strings1 = new ArrayList<>();
        for (int i = 0; i < 21; i++) {
            strings1.add("内容内容内容内容内容内容内容内容内容内容内容内容" + (i + 1));
        }
        SnapAdapter1 snapAdapter2 = new SnapAdapter1();
        rcy_snap_2.setAdapter(snapAdapter2);
        snapAdapter2.setNewData(strings1);
    }

    @Override
    protected void release() {

    }


    final class SnapAdapter extends BaseQuickAdapter<Integer, BaseViewHolder> {
        public SnapAdapter() {
            super(R.layout.item_snap);
        }

        @Override
        protected void convert(BaseViewHolder helper, Integer item) {
            GlideUtil.loadImage(((ImageView) helper.itemView), item);
        }
    }

    final class SnapAdapter1 extends BaseQuickAdapter<String, BaseViewHolder> {
        public SnapAdapter1() {
            super(R.layout.item_snap_text);
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            ((TextView) helper.itemView).setText(item);
        }
    }
}
